﻿using IdentityModel.Client;
using IdentityServer4.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace IdentityServer4Service.Controllers
{
    [ApiController]
    [Route("get_token")]
    public class TokenController : ControllerBase
    {
        private readonly IHttpClientFactory _httpClientFactory;

        public TokenController(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        public async Task  Get()
        {
            var request = new PasswordTokenRequest
            {
                Address = "http://localhost:5000/connect/token",
                ClientId = "client",
                ClientSecret = "secret",
                Scope = "api1",
                UserName = "Admin",
                Password = "123456",
            };
            var tokenResponse = await _httpClientFactory.CreateClient().RequestPasswordTokenAsync(request);
        }
    }
}
